package com.example.demo;

import lombok.experimental.Wither;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.test.context.junit4.SpringRunner;

@SpringBootTest
@RunWith(SpringRunner.class)
public class OpForSet {
    @Autowired
    private RedisTemplate redisTemplate;
    @Test
    public void set1(){
        String[] s=new String[]{"str1","str2"};
        System.out.println(redisTemplate.opsForSet().add("Set1",s));
        System.out.println(redisTemplate.opsForSet().add("Set1","1","2","3"));
    }

    @Test
    public void set2(){
        String[] s=new String[]{"str1","str2"};
        System.out.println(redisTemplate.opsForSet().add("Set2",s));
        System.out.println(redisTemplate.opsForSet().remove("set2",s));
    }

    @Test
    public void set3(){
        String[] s=new String[]{"str1","str2"};
        System.out.println(redisTemplate.opsForSet().add("Set3",s));
        System.out.println(redisTemplate.opsForSet().pop("Set3"));
        System.out.println(redisTemplate.opsForSet().members("Set3"));
    }
    @Test
    public void set4(){
        String[] s=new String[]{"str4","str2"};
        System.out.println(redisTemplate.opsForSet().add("Set4",s));
        redisTemplate.opsForSet().move("Set4","str2","Set4to2");
        System.out.println(redisTemplate.opsForSet().members("Set4"));
        System.out.println(redisTemplate.opsForSet().members("Set4to2"));
    }
    @Test
    public void set5(){
        String[] s=new String[]{"str1","str2"};
        System.out.println(redisTemplate.opsForSet().add("Set5",s));
        System.out.println(redisTemplate.opsForSet().size("Set5"));
    }
    @Test
    public void set6(){
        String[] s=new String[]{"str1","str2"};
        System.out.println(redisTemplate.opsForSet().add("Set6",s));
        System.out.println(redisTemplate.opsForSet().members("Set6"));
    }
    @Test
    public void set7(){
        String[] s=new String[]{"str1","str2"};
        System.out.println(redisTemplate.opsForSet().add("Set7",s));
        Cursor<Object> cursor=redisTemplate.opsForSet().scan("Set7", ScanOptions.NONE);
        while (cursor.hasNext()){
            System.out.println(cursor.next());
        }
    }




}
